package com.zxy.fmmall.service.impl;

import com.zxy.fmmall.dao.UserAddrMapper;
import com.zxy.fmmall.entity.UserAddr;
import com.zxy.fmmall.service.UserAddrService;
import com.zxy.fmmall.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class UserAddrServiceImpl implements UserAddrService {
    @Autowired
    private UserAddrMapper userAddrMapper;


    @Override
    public ResultVo selectAddressDetailsByAddrId(String addrId) {
        Example example = new Example(UserAddr.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("addrId",addrId);
        UserAddr userAddr = userAddrMapper.selectOneByExample(example);
        return ResultVo.ok().data("userAddr",userAddr);
    }

    @Transactional(propagation = Propagation.SUPPORTS)
    public ResultVo listAddrsByUserId(String userId) {
        Example example = new Example(UserAddr.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("userId", userId);
        criteria.andEqualTo("status",1);
        List<UserAddr> userAddrs = userAddrMapper.selectByExample(example);
        return ResultVo.ok().data("userAddrs", userAddrs);
    }

}
